<?
include_once("secure/connect.php");
include_once("secure/functions.php");
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Document sans nom</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<?
if ($_POST['date_debut_Y'])
	{
	$_POST['date_debut']=$_POST['date_debut_Y']."-".$_POST['date_debut_m']."-".$_POST['date_debut_d'];
	$_POST['date_fin']=$_POST['date_fin_Y']."-".$_POST['date_fin_m']."-".$_POST['date_fin_d'];
	}

if (!$_POST['date_debut']) {$_POST['date_debut']=date("Y-m-d");}
if (!$_POST['date_fin']) {$_POST['date_fin']=date("Y-m-d");}
if (!$_POST['type_fact']) {$_POST['type_fact']=0;}
if (!$_POST['type_recherche']) {$_POST['type_recherche']="dernieres";}

?>
<body>
<p>Trouver une fiche de location
  <script language="javascript" type="text/javascript">
<!--
function refresh_field(selected_username)
{
	opener.document.forms['ecriture_comptable'].id_fiche_loc_link.value = selected_username;
	opener.focus();
	window.close();

}
//-->
</script>

</p>
<form method="post" name="search" action="?">

				<p>
    <input type="radio" name="type_recherche" id="dernieres" value="dernieres" <? if ($_POST['type_recherche']=="dernieres")
				  	{echo "checked";} ?>>
    100 dernières<br>
    <input type="radio" name="type_recherche" id="critere" value="criteres" <? if ($_POST['type_recherche']=="criteres")
				  	{echo "checked";} ?>>
  crit&egrave;res de reherche:<table border="1">
    <tr><td>
                  <input name="dates" type="checkbox" value="1" <? if ($_POST['dates']) {print "checked";} ?>>
                  entre le
                  <? dates_select_trois($_POST['date_debut'], date("Y")-4, date("Y")+1, "date_debut"); ?>
                  et le
                  <? dates_select_trois($_POST['date_fin'], date("Y")-4, date("Y")+1, "date_fin"); ?>
                  <br>
                  client
                  <input name="contacts" type="text" id="contacts" value="<? print $_POST['contacts'] ?>" onFocus="document.getElementById('critere').checked=true">
                  <br>
                  type de contrat
                  <? mk_list_table("type_fact",$_POST['type_fact'],"SELECT id, nom FROM fiches_loc_types WHERE active ='1' ORDER BY id", "id", "nom", $db, TRUE); ?>
                  </td></tr></table>
                  <input type="submit" name="Submit" value="recherche">
  </p>
				<p>
				  <?
				  if ($_POST['type_recherche']=="dernieres")
				  	{
					$sql="SELECT fiches_loc.id, CONCAT(fiches_loc.id,' - ',contacts.prenom,' ',contacts.nom,'  \"',nom_event,'\" (',date_debut,')') as nom FROM fiches_loc, contacts WHERE contacts.id=fiches_loc.client ORDER BY id DESC LIMIT 0,100 ";
					}
				elseif ($_POST['type_recherche']=="criteres")
					{
					$search=FALSE;
					$where="AND (";
					if ($_POST['contacts'])
						{
						$search=TRUE;
						$where=$where." (contacts.prenom LIKE '%".$_POST['contacts']."%' OR contacts.nom LIKE '%".$_POST['contacts']."%' OR contacts.societe LIKE '%".$_POST['contacts']."%' OR contacts.ean LIKE '%".$_POST['contacts']."%' OR fiches_loc.nom_event LIKE '%".$_POST['contacts']."%') AND";
						}
					if ($_POST['type_fact'])
						{
						$search=TRUE;
						$where=$where." type_fact='".$_POST['type_fact']."' AND";
						}
					if ($_POST['dates']) 
						{
						$search=TRUE;
						$where=$where." ((date_out<='".$_POST['date_debut']."' AND date_in>='".$_POST['date_debut']."') 
						OR (date_out<='".$_POST['date_fin']."' AND date_in>='".$_POST['date_fin']."') 
						OR (date_out>='".$_POST['date_debut']."' AND date_in<='".$_POST['date_fin']."')) AND";
						}
					$where=substr($where,0,-3);
					$where=$where.")";
					if (!$search) {$where=FALSE;}
					//print $where;
					$sql="SELECT fiches_loc.id, CONCAT(fiches_loc.id,' - ',contacts.prenom,' ',contacts.nom,'  \"',nom_event,'\" (',date_debut,')') as nom FROM fiches_loc, contacts WHERE contacts.id=fiches_loc.client ".$where." ORDER BY id DESC LIMIT 0,100 ";
					}
				  mk_list_table_class("fiche_loc","",$sql, "id", "nom", $db, FALSE, "champs"); ?>
                  <input type="submit" onClick="refresh_field(this.form.fiche_loc.options[this.form.fiche_loc.selectedIndex].value);return false;" name="use2" value="S&eacute;lectionner" />
                  <br />
  
                  <a href="javascript:window.close();" class="genmed">Fermer la Fenêtre</a> </p>
</form>
</body>
</html>
